<template>
  <div class="page-table">
    <div class="table">
      <div class="title-bar">
        <h2>奖金提成信息【{{$route.query.name}}网点用户】</h2>
        <el-form size="mini">
          <ad-month-select v-model="revenueSearchQuery.month" @select="revenueGetInitList()"/>
        </el-form>
      </div>
      <ad-table :data="revenueList" v-loading="revenueInitLoading" border u-table
                :data-changes-scroll-top="revenueIsScrollTop"
                @row-click="revenueSelectRow" :searchQuery="revenueSearchQuery"
                @sort-change="revenueSortInitList" @filter-change="revenueFilterInitList" :height="topTableHeight">
        <ad-table-column label="序号" type="index" ctype="index" fixed/>
        <ad-table-column label="用户名" prop="nickName" w="4c1f"/>
        <ad-table-column label="用户账号" prop="account" w="4c1f"/>
        <ad-table-column label="联系电话" prop="phone" w="4c1f"/>
        <ad-table-column label="制单工资" w="4c1f">
          <template v-slot="{row}">
            <template v-if="row.createCount > 0">
              <value :model="row" prop="createFee"/>元(<value :model="row" prop="createCount"/>台)
            </template>
            <template v-else>-</template>
          </template>
        </ad-table-column>
        <ad-table-column label="提短工资" w="4c1f">
          <template v-slot="{row}">
            <template v-if="row.pickFreeCount > 0">
              <value :model="row" prop="pickFreeFee"/>元(<value :model="row" prop="pickFreeCount"/>台)
            </template>
            <template v-else>-</template>
          </template>
        </ad-table-column>
        <ad-table-column label="提车指派工资" w="6c1f">
          <template v-slot="{row}">
            <template v-if="row.pickCount > 0">
              <value :model="row" prop="pickFee"/>元(<value :model="row" prop="pickCount"/>台)
            </template>
            <template v-else>-</template>
          </template>
        </ad-table-column>
        <ad-table-column label="验车工资" w="4c1f">
          <template v-slot="{row}">
            <template v-if="row.verifyCount > 0">
              <value :model="row" prop="verifyFee"/>元(<value :model="row" prop="verifyCount"/>台)
            </template>
            <template v-else>-</template>
          </template>
        </ad-table-column>
        <ad-table-column label="发运工资" w="4c1f">
          <template v-slot="{row}">
            <template v-if="row.transportCount > 0">
              <value :model="row" prop="transportFee"/>元(<value :model="row" prop="transportCount"/>台)
            </template>
            <template v-else>-</template>
          </template>
        </ad-table-column>
        <ad-table-column label="签收工资" w="4c1f">
          <template v-slot="{row}">
            <template v-if="row.signCount > 0">
              <value :model="row" prop="signFee"/>元(<value :model="row" prop="signCount"/>台)
            </template>
            <template v-else>-</template>
          </template>
        </ad-table-column>
        <ad-table-column label="交付工资" w="4c1f">
          <template v-slot="{row}">
            <template v-if="row.deliveryCount > 0">
              <value :model="row" prop="deliveryFee"/>元(<value :model="row" prop="royaltyCount"/>台)
            </template>
            <template v-else>-</template>
          </template>
        </ad-table-column>
        <ad-table-column label="提成工资" w="4c1f">
          <template v-slot="{row}">
            <template v-if="row.royaltyCount > 0">
              <value :model="row" prop="royaltyFee"/>元(<value :model="row" prop="royaltyCount"/>台)
            </template>
            <template v-else>-</template>
          </template>
        </ad-table-column>
        <ad-table-column label="奖金基数" prop="bonusBase" w="4c1f"/>
        <ad-table-column label="提成基数" prop="royaltyBase" w="4c1f"/>
        <ad-table-column label="操作" w="4c1f" width="220" prefix="right">
          <template v-slot="{row}">
            <div class="op">
<!--              <el-button type="text" class="op-btn" @click="openRevenueAdder(row)">配置</el-button>-->
              <el-button type="text" class="op-btn" v-if="hasPerm('sysUser:updatePwd')" @click="$refs.updPwd.open(row.userId)">修改密码</el-button>
              <el-button type="text" class="op-btn" v-if="hasPerm('sysUser:delete')" @click="updDel(row)">删除</el-button>
            </div>
          </template>
        </ad-table-column>
        <ad-table-column width="auto"/>
      </ad-table>
    </div>

    <el-row :gutter="10" style="margin-top: 10px">
      <el-col :span="12">
        <div class="table">
          <div class="title-bar">
            <h2>线路信息</h2>
            <div class="op">
              <el-button size="mini" type="primary" plain @click="priceList.visible = true">提送费列表</el-button>
            </div>
          </div>
<!--          revenueList-->
          <ad-table :data="[]" :show-summary="revenueSummary" v-loading="revenueInitLoading" border u-table
                    :data-changes-scroll-top="revenueIsScrollTop"
                    @row-click="revenueSelectRow" :searchQuery="revenueSearchQuery"
                    @sort-change="revenueSortInitList" @filter-change="revenueFilterInitList" :height="bottomTableHeight">
            <ad-table-column label="序号" type="index" ctype="index" fixed/>
            <ad-table-column label="出发地" prop="nickName" w="4c1f"/>
            <ad-table-column label="目的地" prop="nickName" w="4c1f"/>
            <ad-table-column label="承运费用" prop="nickName" w="4c1f"/>
            <ad-table-column label="公司名称" prop="nickName" w="4c1f"/>
            <ad-table-column label="联系人" prop="nickName" w="4c1f"/>
            <ad-table-column label="联系电话" prop="nickName" w="4c1f"/>
            <ad-table-column label="添加人" prop="nickName" w="4c1f"/>
            <ad-table-column width="auto"/>
          </ad-table>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="table">
          <div class="title-bar">
            <h2>客户供应商列表</h2>
          </div>
          <ad-table :data="companyList" :show-summary="companySummary" v-loading="companyInitLoading" border u-table
                    :data-changes-scroll-top="companyIsScrollTop"
                    @row-click="companySelectRow" @selection-change="companySelectRows"
                    :searchQuery="companySearchQuery" @search="companyGetInitList"
                    @sort-change="companySortInitList" @filter-change="companyFilterInitList"
                    @table-body-scroll="companyGetMoreList" :height="bottomTableHeight">
            <ad-table-column label="序号" type="index" ctype="index" fixed/>
            <ad-table-column label="公司名称" prop="name" w="4c1f"/>
            <ad-table-column label="类型" prop="companyType" dictName="customer_type" filterable w="2c1f"/>
            <ad-table-column label="审核状态" prop="hasCheck" dictName="yes_or_no" filterable w="4c1f"/>
            <ad-table-column label="是否月结" prop="companyNature" dictName="yes_or_no" filterable w="4c1f"/>
            <ad-table-column label="下单台数" prop="orderCount" w="4c"/>
            <ad-table-column label="承运台数" prop="transportCount" w="4c"/>
            <ad-table-column label="添加时间" prop="createTime" ctype="datetime" sortable w="7c1f"/>
            <ad-table-column label="添加人" prop="createUserName" w="4c1f"/>
            <ad-table-column label="审核人" prop="checkUserName" w="4c1f"/>
          </ad-table>
        </div>
      </el-col>
    </el-row>
    <el-dialog title="奖金提成配置" :visible.sync="revenueAdder.visible" custom-class="ad-dialog" width="558px">
      <revenue-adder :mode="revenueAdder.mode" :id="revenueSelectedRowId" :visible.sync="revenueAdder.visible" @saved="revenueSaved"/>
    </el-dialog>
    <el-dialog title="提送费列表" :visible.sync="priceList.visible" custom-class="ad-dialog" width="944px">
      <price-list :visible.sync="priceList.visible"/>
    </el-dialog>
    <updPwd ref="updPwd" @ok="companyApiGetList" />
  </div>
</template>

<script>
import Value from '@/components/AdValue'
import AdTable from '@/components/AdTable'
import AdTableColumn from '@/components/AdTable/AdTableColumn'
import AdMonthSelect from '@/components/AdMonthSelect'
import revenueAdder from './dialog/revenueAdder'
import priceList from './dialog/priceList'
import adTable from '@/mixins/adTable'
import Date from '@/utils/datetime'
import {getList as revenueApiGetList} from '@/api/revenue'
import {getList as companyApiGetList} from '@/api/revenue/company'
import updPwd from '@/views/system/userList/updPwd.vue'
import { sysUserDelete } from '@/api/modular/system/userManage'

export default {
  components: { updPwd, Value, AdTable, AdTableColumn, AdMonthSelect, revenueAdder, priceList },
  dicts: ['customer_type','yes_or_no'],
  mixins: [adTable([
    {name: 'revenue'},
    // {name: 'line'},
    {name: 'company'}
  ])],
  watch:{
    $route() {
      this.getList()
    }
  },
  data() {
    return {
      topTableHeight: 120,
      bottomTableHeight: document.documentElement.clientHeight - 356,
      revenueSearchable: false,
      companySearchable: false,
      priceList: {
        visible: false
      }
    }
  },
  created() {
        this.getList()
  },
  methods: {
    revenueApiGetList, companyApiGetList,
    openRevenueAdder(row) {
      this.revenueSelectedRowId= row.userId
      this.revenueEdit()
    },
    getList(){
      this.revenueSearchQuery = {id: this.$route.query.id, month: new Date().strftime('%G%m')}
      this.companySearchQuery = {id: this.$route.query.id}
      this.revenueGetInitList()
      this.companyGetInitList()
    } ,
    updDel(record){
      this.$confirm('确定删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        sysUserDelete({ id:record.userId,status:2 })
          .then(res => {
            if (res.success) {
              this.$message.success('删除成功')
              this.revenueGetInitList()
            } else {
              this.$message.error('删除失败：' + res.message)
            }
          })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.page-table { margin-top: 0; padding-top: 10px; background: #eee; }
.table { padding: 0 20px 20px; background: #fff; }
.title-bar { display: flex; height: 40px; background: #fff; align-items: center;
  h2 { font-size: 14px; font-weight: bold; }
  .op { margin-left: auto; }}
</style>